<?php

namespace teach\controllers;


use teach\service\Video;
use teach\util\helper\ResponseHelper;
use Yii;
use yii\filters\VerbFilter;
use yii\web\Controller;

class VideoController extends Controller
{
    public $enableCsrfValidation = false;

    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::class,
                'actions' => [
                    'list' => ['post'],
                ],
            ],
        ];
    }

    /**
     * 查找视频的列表
     * @return \yii\web\Response
     */
    public function actionList()
    {
//        $request = Yii::$app->request;
//        $cid = $request->post('cid');
//
//        $page = $request->post('page');
//        $page = $page ? $page : 1;
//
//        $map = ' status = 1 ';
//        if ($cid) {
//            $map .= ' AND cid = ' . $cid;
//        }
//
//        $videos = new Video();
//        $videoList = $videos->videoList($map, $page, $pre_page = 10);
        //去掉此功能
        $videoList = [];

        $jsonData = ResponseHelper::buildJsonData(200, '成功', $videoList);

        return $this->asJson($jsonData);

    }


    /**
     * 点击播放量加一
     * @return \yii\web\Response
     */
    public function actionIncrease()
    {
        $request = Yii::$app->request;
        $vid = $request->post('vid');

        $msg = '';
        $flag = false;
        if (!$vid) {
            $msg = 'vid 视频ID不能为空';
        } else {
            $flag = true;
        }

        if (!$flag) {
            $jsonData = ResponseHelper::buildJsonData(400, $msg);
        } else {

            $videos = new Video();
            $map = " status = 1 AND id = " . $vid;
            $videos->videoIncrease($map);

            $jsonData = ResponseHelper::buildJsonData(200, '成功');
        }

        return $this->asJson($jsonData);
    }
}
